<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>properties | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'properties.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/properties.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/properties.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/properties.html" rel="nofollow" target="_blank">../en/properties.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="mapping.html">Mapping</a></span>
»
<span class="breadcrumb-link"><a href="mapping-params.html">Mapping parameters</a></span>
»
<span class="breadcrumb-node"><code class="literal">properties</code></span>
</div>
<div class="navheader">
<span class="prev">
<a href="position-increment-gap.html">« <code class="literal">position_increment_gap</code></a>
</span>
<span class="next">
<a href="search-analyzer.html"><code class="literal">search_analyzer</code> »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="properties"></a><code class="literal">properties</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/properties.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Type mappings, <a class="xref" href="object.html" title="Object datatype"><code class="literal">object</code> fields</a> and <a class="xref" href="nested.html" title="Nested datatype"><code class="literal">nested</code> fields</a>
contain sub-fields, called <code class="literal">properties</code>. These properties may be of any
<a class="xref" href="mapping-types.html" title="Field datatypes">datatype</a>, including <code class="literal">object</code> and <code class="literal">nested</code>.  Properties can
be added:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
explicitly by defining them when <a class="xref" href="indices-create-index.html" title="Create index API">creating an index</a>.
</li>
<li class="listitem">
explicitly by defining them when adding or updating a mapping type with the <a class="xref" href="indices-put-mapping.html" title="Put mapping API">PUT mapping</a> API.
</li>
<li class="listitem">
<a class="xref" href="dynamic-mapping.html" title="Dynamic Mapping">dynamically</a> just by indexing documents containing new fields.
</li>
</ul>
</div>
<p>Below is an example of adding <code class="literal">properties</code> to a mapping type, an <code class="literal">object</code>
field, and a <code class="literal">nested</code> field:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index
{
  "mappings": {
    "properties": { <a id="CO355-1"></a><i class="conum" data-value="1"></i>
      "manager": {
        "properties": { <a id="CO355-2"></a><i class="conum" data-value="2"></i>
          "age":  { "type": "integer" },
          "name": { "type": "text"  }
        }
      },
      "employees": {
        "type": "nested",
        "properties": { <a id="CO355-3"></a><i class="conum" data-value="3"></i>
          "age":  { "type": "integer" },
          "name": { "type": "text"  }
        }
      }
    }
  }
}

PUT my_index/_doc/1 <a id="CO355-4"></a><i class="conum" data-value="4"></i>
{
  "region": "US",
  "manager": {
    "name": "Alice White",
    "age": 30
  },
  "employees": [
    {
      "name": "John Smith",
      "age": 34
    },
    {
      "name": "Peter Brown",
      "age": 26
    }
  ]
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/776.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO355-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Properties in the top-level mappings definition.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO355-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Properties under the <code class="literal">manager</code> object field.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO355-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>Properties under the <code class="literal">employees</code> nested field.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO355-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>An example document which corresponds to the above mapping.</p>
</td>
</tr>
</table>
</div>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>The <code class="literal">properties</code> setting is allowed to have different settings for fields
of the same name in the same index.  New properties can be added to existing
fields using the <a class="xref" href="indices-put-mapping.html" title="Put mapping API">PUT mapping API</a>.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_dot_notation"></a>Dot notation<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/properties.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Inner fields can be referred to in queries, aggregations, etc., using <em>dot
notation</em>:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET my_index/_search
{
  "query": {
    "match": {
      "manager.name": "Alice White"
    }
  },
  "aggs": {
    "Employees": {
      "nested": {
        "path": "employees"
      },
      "aggs": {
        "Employee Ages": {
          "histogram": {
            "field": "employees.age",
            "interval": 5
          }
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/777.console"></div>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>The full path to the inner field must be specified.</p>
</div>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="position-increment-gap.html">« <code class="literal">position_increment_gap</code></a>
</span>
<span class="next">
<a href="search-analyzer.html"><code class="literal">search_analyzer</code> »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>